<%-- 
    Document   : role
    Created on : 2016-7-1, 14:13:07
    Author     : 52461
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../link.jsp"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" src="${base}/js/highcharts/highcharts.js" ></script>
        <script type="text/javascript" src="${base}/js/mychartoption.js" ></script>
        <title>JSP Page</title>
        <style>
            * { margin:0; padding:0;}
            body { margin:0; padding:0;  font-family:"微软雅黑";}
            table td { padding:3px 1px;}
            .title { font-size:24px; text-align:center; width:40%;}
            .check_info th { border-bottom:1px #666 solid; padding-bottom:5px;}
            /*.check_info td,th{ padding-left:20px;}*/
            .hx{ border-right:  1px #666 solid}
        </style>
    </head>
    <body  ng-app="jyjgManager" ng-controller="jyjgCtrl" >
        <table width="1000px" style=" margin:0 auto;font-size:{{fontSize}}" cellpadding="0" cellspacing="0">
            <tr>
                <td colspan="2">
                    <div style="text-align: center">
                        <h4 style="font-weight: bold;font-size:24px;" ng-bind="reportName"></h4>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2"> 
                    <table cellpadding="0" cellspacing="0" width="100%" style=" border-bottom:1px #666 solid;font-size:{{fontSize}}">
                        <tr>
                            <td align="right" width="80px">姓名：</td>
                            <td contenteditable="true" align="left" width="100px">{{info.PATIENTNAME}}</td>
                            <td align="right">病历号：</td>
                            <td contenteditable="true" align="left" width="100px">{{info.PATIENTID}}</td>
                            <td align="right">科室：</td>
                            <td contenteditable="true" align="left" width="100px">{{info.SECTION}}</td>
                            <td align="right">样本号：</td>
                            <td contenteditable="true" align="left" width="120px">{{sampleNo}}</td>
                        </tr>
                        <tr>
                            <td align="right">性别：</td>
                            <td contenteditable="true" align="left">{{info.SEX}}</td>
                            <td align="right">病房号：</td>
                            <td contenteditable="true" align="left"></td>
                            <td align="right">送检医生：</td>
                            <td contenteditable="true" align="left">{{info.SJYS}}</td>
                            <td align="right">标本类型：</td>
                            <td contenteditable="true" align="left">{{info.SAMPLE}}</td>
                        </tr>
                        <tr>
                            <td align="right">年龄：</td>
                            <td contenteditable="true" align="left">{{info.AGE}}</td>
                            <td align="right">床号：</td>
                            <td contenteditable="true" align="left">{{info.BED_NO}}</td>
                            <td align="right">机器型号：</td>
                            <td contenteditable="true" align="left">{{results[0].DEVICEID}}</td>
                            <td align="right">检验项目：</td>
                            <td contenteditable="true" align="left">{{info.EXAMINAIM}}</td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr style="border-bottom:1px #666 solid;height:400px;">
                <td colspan="2" valign="top">
                    <table width="100%">
                        <tr>
                            <td valign="top"  style=" padding-right:0;">
                                <table cellpadding="0" cellspacing="0" width="100%" class="check_info" style="font-size:{{fontSize}}">
                                    <thead>
                                        <tr>
                                            <th align="left">项目简称</th>
                                            <th align="left">项目名称</th>

                                            <th></th>
                                            <th align="left">结果</th>

                                            <th align="left">单位</th>
                                            <th align="left">参考范围</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ng-repeat="le in left| filter:{RESULTFLAG:'0'}">
                                            <!--<td>{{$index+1}}</td>-->
                                            <td>{{le.TESTID}}</td>
                                            <td>{{le.CHINESENAME}}</td>
                                            <td>{{le.HL_STATUS}}</td>
                                            <td>{{le.TESTRESULT}}</td>

                                            <td>{{le.UNIT}}</td>
                                            <td ng-class="{
                                            true: 'hx', false: 'inactive'}
                                                [isActive]">{{le.fanwei}}</td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                            <td valign="top" style="padding-left:0; margin:0;display:none" id="fenye">
                                <table cellpadding="0" cellspacing="0" width="100%" class="check_info" style="font-size:{{fontSize}}">
                                    <thead>
                                        <tr>
                                            <th align="left">项目简称</th>
                                            <th align="left">项目名称</th>
                                            <th></th>
                                            <th align="left">结果</th>

                                            <th align="left">单位</th>
                                            <th align="left">参考范围</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr ng-repeat="ri in right| filter:{RESULTFLAG:'0'}">
                                            <!--<td>{{$index+15}}</td>-->
                                            <td>{{ri.TESTID}}</td>
                                            <td>{{ri.CHINESENAME}}</td>
                                            <td>{{ri.HL_STATUS}}</td>
                                            <td>{{ri.TESTRESULT}}</td>

                                            <td>{{ri.UNIT}}</td>
                                            <td>{{ri.fanwei}}</td>
                                        </tr>
                                    </tbody>
                                </table>



                            </td>
                        </tr>
                    </table>



                    <div ng-show="chart" style="position:relative; bottom: -20px;margin-top: -30px; ">

                        <div id="wbc"  style="float: left;width:320px;height: 170px;"></div>
                        <div id="rbc"  style="float: left;width:320px;height: 170px;"></div>
                        <div id="plt"  style="float: left;width:320px;height: 170px;"></div>
                        <div style="clear: both"></div>
                    </div>

                    <div ng-show="zftchart">
                        <div style="float: left;width:320px;height: 170px;">
                            <label>WBC</label>
                            <img ng-src="{{WBC}}" />
                        </div>
                        <div   style="float: left;width:320px;height: 170px;">
                            <label>RBC</label>
                            <img ng-src="{{RBC}}" />
                        </div>

                        <div   style="float: left;width:320px;height: 170px;">
                            <label>PLT</label>
                            <img ng-src="{{PLT}}" />
                        </div>
                    </div>
                </td>
            </tr>

            <tr>
                <td colspan="2">
                    <table style="font-size:{{fontSize}}" width="100%">
                        <tr>
                            <td  align="right" width="120px">备注： </td>
                            <td   contenteditable="true" align="left" width="300px">此结果仅对本份检验标本负责</td>
                            <td align="right" width="200px">检验医生<span style="margin-left: 10px;margin-right: 10px;">:</span>{{info.JYYS}}</td>
                            <!--                            
                                                        <td contenteditable="true" align="left" width="80px"></td>
                                                        <td align="right"></td>
                                                        <td contenteditable="true" align="left"width="100px" ></td>-->
                            <td  colspan="" align="right" width="120px">审核人：</td>
                            <td   contenteditable="true" align="left" width="100px">{{info.CHECKOPERATOR}}</td>
                        </tr>
                        <tr>
                            <td align="right" width="120px">检验时间：</td>
                            <td   contenteditable="true" align="left" width="300px">{{results[0].MEASURETIME}}</td>
                            <td align="right" width="200px"></td>
                            <!--                            <td align="right"></td>
                                                        <td contenteditable="true" align="left" width="100px"></td>
                                                        <td align="right"></td>
                                                        <td contenteditable="true" align="left" width="100px"></td>
                                                        <td align="right"></td>
                                                        <td contenteditable="true" align="left" width="120px"></td>-->
                            <td align="right" width="120px">打印日期：</td>
                            <td contenteditable="true" align="left" width="260px">{{date}}</td>
                        </tr>
                    </table>
                </td>

            </tr>

        </table>

    </body>
</html>
<script>
    angular.module("jyjgManager", [])
    .controller("jyjgCtrl", function($scope) {
        var WBC = [];
        var RBC = [];
        var PLT = [];
        $scope.config = {};
        $scope.fontSize = "16px";
        $scope.reportName = "<%=DataCache.getIntance().getConfig().get("hospitalName")%>检验报告单";
        console.log('<%=DataCache.getIntance().getConfig().get("hospitalName")%>');
        if (localStorage.results) {
            $scope.results = JSON.parse(localStorage.results);
            console.table($scope.results);
        }
        if (localStorage.info) {

            $scope.info = JSON.parse(localStorage.info);
        }
        if (localStorage.reprotConfig) {
            $scope.config = JSON.parse(localStorage.reprotConfig);
            console.log($scope.config);
            if ($scope.config.reportName != "") {
                $scope.reportName = $scope.config.reportName;
            }
            if ($scope.config.fontSize != "") {
                $scope.fontSize = $scope.config.fontSize;
            }
            //console.log($scope.config.reportName + "  " + $scope.fontSize);
        }


        var checkChart = function() {
           // alert(typeof WBC == "string");
            if (typeof WBC == "string") {
                $scope.WBC = "data:image/jpg;base64," + WBC;
                $scope.RBC = "data:image/jpg;base64," + RBC;
                $scope.PLT = "data:image/jpg;base64," + PLT;
                $scope.zftchart = true;
            } else {
                var NEWWBC = [],
                    NEWRBC = [],
                    NEWPLT = [];
                if (WBC.length > 0) {
                    $scope.chart = true;
                    var WBCindexs = [];
                    for (var i in WBC) {
                        WBCindexs.push(i);
                        NEWWBC.push(parseFloat(WBC[i]));
                    }
                    var RBCindexs = [];
                    for (var i in RBC) {
                        RBCindexs.push(i);
                        NEWRBC.push(parseFloat(RBC[i]));
                    }
                    var PLTindexs = [];
                    for (var i in PLT) {
                        PLTindexs.push(i);
                        NEWPLT.push(parseFloat(PLT[i]));
                    }
                    var baso;
                    for (var i in $scope.results) {
                        if ($scope.results[i].TESTID == "BASOR") {
                            baso = true;
                            break;
                        }
                    }

                    if (baso) {
                        $('#wbc').highcharts(getChart2("WBC/BASO", WBCindexs, NEWWBC));
                    } else {
                        $('#wbc').highcharts(getChart2("WBC", WBCindexs, NEWWBC));
                    }


                    $('#rbc').highcharts(getChart2("RBC", RBCindexs, NEWRBC));
                    $('#plt').highcharts(getChart2("PLT", PLTindexs, NEWPLT));
                }

            }
        }

        $scope.sampleNo = localStorage.sampleNo;
        $scope.date = localStorage.date;
        $scope.left = [];
        $scope.right = [];
        $scope.isActive = false;
        $scope.copyResult = angular.copy($scope.results);
        //console.table($scope.results);
        for (var i = 0; i < $scope.copyResult.length; i++) {

            if ($scope.copyResult[i].TESTID == 'image#WBC') {
                if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     WBC = $scope.copyResult[i].TESTRESULT.toString();
                }else{
                    WBC = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
                // console.log(WBC+"--------------------");
                // $scope.results.splice(i,1);
                // console.log(WBC);
            } else if ($scope.copyResult[i].TESTID.toString() == 'image#RBC') {
               if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     RBC = $scope.copyResult[i].TESTRESULT.toString();
                }else{
                    RBC = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
                RBC = $scope.copyResult[i].TESTRESULT.split(" ");
                //  $scope.results.splice(i,1);
            } else if ($scope.copyResult[i].TESTID == 'image#PLT') {
                
                 if($scope.copyResult[i].RESULTFLAG=='2'){
                    
                     PLT = $scope.copyResult[i].TESTRESULT.toString();
                }else{
                    PLT = $scope.copyResult[i].TESTRESULT.toString().split(" ");
                }
               
                //  $scope.results.splice(i,1);
            }
        }

        for (var i = 0; i < $scope.results.length; i++) {

            if ($scope.results[i].TESTID == 'image#WBC') {
                $scope.results.splice(i, 1);
                break;
            }
        }

        for (var i = 0; i < $scope.results.length; i++) {

            if ($scope.results[i].TESTID == 'image#RBC') {
                $scope.results.splice(i, 1);
                break;
            }
        }
        for (var i = 0; i < $scope.results.length; i++) {

            if ($scope.results[i].TESTID == 'image#PLT') {
                $scope.results.splice(i, 1);
                break;
            }
        }




        console.log($scope.results.length + "99999999999999999999");
        if ($scope.results.length > 14) {
            for (var i = 0; i < Math.ceil($scope.results.length / 2); i++) {
                var l = $scope.results[i];
                $scope.left.push(l);
            }
            console.log(Math.ceil($scope.results.length / 2)+'-------------------------')
            //console.table($scope.results);
            for (var j = Math.ceil($scope.results.length / 2); j < $scope.results.length; j++) {
                var r = $scope.results[j];
                $scope.right.push(r);
            }
            console.log($scope.left);
            console.log($scope.right);
            $("#fenye").show();
            $(".check_info").width("50%");
            $("#hh").addClass("hx");
            $scope.isActive = true;
        } else {
            for (var i = 0; i < $scope.results.length; i++) {
                var l = $scope.results[i];
                $scope.left.push(l);
            }
        }


        checkChart();
        setTimeout(function() {
            window.print();
            window.close();
        }, 1000)



    })

</script>
